/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jsf.session;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import jpa.entities.Staff;

/**
 *
 * @author KenShin
 */
@Stateless
public class StaffFacade extends AbstractFacade<Staff> {
    @PersistenceContext(unitName = "SupportiveLearning-ejbPU")
    private EntityManager em;
    private Staff staff;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public StaffFacade() {
        super(Staff.class);
    }

    public Staff checkUserValid(String UserName, String Password) {
        staff = null;
         List<Staff> results = em.createQuery("SELECT s FROM Staff s WHERE s.userName = :userName AND s.password = :password")
           .setParameter("userName", UserName)
           .setParameter("password", Password)
           .getResultList();
         
         if (!results.isEmpty() ) {
           staff = results.get(0);
        }
        return staff;
    }
    
}
